#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

pthread_t thread1;
int  pid;
int i=0;
int lock=1;
char *str;

/* The thread's  main()*/
void *threadmain(void *arg){
    str=(char*)arg;
    while (i<5) {
        if (lock==1) {
            printf("In the thread, The pid= %d and %s was passed\n",getpid(),str);
            lock=0;
            i++;
            sleep(1);
        }
    }
    return;   
}

int  main(void){         
    pthread_create( &thread1, NULL,threadmain, "JUST A TEST");
    while (lock==1) {
        sleep(1);
    }
    while (i<5) {
        if (lock==0) {
            printf("In main, The pid= %d\n",getpid());
            lock=1;
            i++;
            sleep(0);
        }
    }
    pthread_join(thread1,NULL);
    return 0;
}